package com.server;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.Helper.ReservationHelper;

public class ModFlightServlet extends CustomerServlet
{
	private static final long serialVersionUID = 1L;

	@Override
	//@requires HttpServletRequest !=NULL,  HttpServletResponse !=NULL ;
    //@assignable username,resID,flightID,id,msg;
    //@ensures 
	//@signals_only RuntimeException, IOException,ServletException;
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException
	{
		ConnectDB();

		String username = req.getParameter("username");
		String resID = req.getParameter("resID");
		String flightID = req.getParameter("r1");
		int id = Integer.parseInt(resID);
		String msg = null;
		
		try //connect to the server and modify the reservation
		{			
			ReservationHelper.Setup(connection, username);
			ReservationHelper.ModFlight(flightID, id);

			msg = "Reservation modified";
		} 
		catch (SQLException e) 
		{
			e.printStackTrace();
		}
		
		req.setAttribute("username", username);	
		req.setAttribute("msg", msg);
		req.setAttribute("resID", id);
		req.getRequestDispatcher("reservation/ModifiedResult.jsp").forward(req, resp);
	}

}

